<?php

use yii\db\Migration;
use yii\db\Schema;

/**
 * Class m180321_071433_CREAT_DB_DOWNLOAD
 */
class m180321_071433_CREAT_DB_DOWNLOAD extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

        // 下载信息表
        $this->createTable('room_download', [
            "id" =>           Schema::TYPE_PK,
            "cruise_id"=>    Schema::TYPE_INTEGER.   "(9) NOT NULL COMMENT '所属邮轮'",
            "name" =>         Schema::TYPE_STRING.    "(255) NULL COMMENT '文件名'",
            "path" =>         Schema::TYPE_STRING.    "(255) NULL COMMENT '文件存储路径'",
            "download_id"=>   Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '下载人id'",
            "num"=>           Schema::TYPE_INTEGER.   "(10) DEFAULT '1' COMMENT '下载次数'",
            "remark"=>        Schema::TYPE_STRING.    "(512) NULL COMMENT '备注'", 
            "down_time"=>     Schema::TYPE_DATETIME.   " NULL COMMENT '下载时间'",
            "status" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>      Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" =>   Schema::TYPE_DATETIME.  " NULL",
            "updated_at" =>   Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",

        ], $tableOptions);

        $this->addColumn('{{room_download}}', 'template_id', Schema::TYPE_INTEGER. "(2) NULL COMMENT '模板类型' ");
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        echo "m180321_071433_CREAT_DB_DOWNLOAD cannot be reverted.\n";

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m180321_071433_CREAT_DB_DOWNLOAD cannot be reverted.\n";

        return false;
    }
    */
}
